Graphic & Visualization

matplotlib
https://matplotlib.org/stable/gallery/index
import matplotlib.pyplot as plt
y=[1, 2, 2, 4, 6, 8]
plt.plot(y)
plt.show()
x=[3, 4, 5, 6, 7, 8]
plt.plot(x, y, 'rx-', ms=10, mfc="None")
plt.show()
plot(x, y): x축 설정하지 않을 시, default로 index 사용
import matplotlib.pyplot as plt
import numpy as np
import os
path=os.getcwd()
path+='/stars.txt'
data=np.loadtxt(path, float)
# 1
x=data[:, 0]
# 2
y=data[:, 1]
# label latex (r'$\Psi$')
plt.xlim([2000, 4000])
plt.xlabel(r'$x$ label')
plt.ylabel(r'$y$ label')
plt.plot(x, y, 'ro', ms=2)
plt.show()
fp=open("test_file.dat", "w")
x=np.linspace(-2*np.pi, 2*np.pi, 100)
y=np.cos(x)
for i in range(len(x)):
print("%e %e" %(x[i], y[i]), file=fp)
fp.close()
without numpy array and matplotlib.pyplot
from pylab import plot, show
from math import sin
from numpy import linspace
xpoints=[]
ypoints=[]
for x in linspace(0, 10, 100):
xpoints.append(x)
ypoints.append(sin(x))
plot(xpoints, ypoints)
show()
히트맵
from pylab import imshow, show
from numpy import loadtxt
data=loadtxt("circular.txt", float)
imshow(data, origin='lower') # origin='lower' (0, 0)
# jet(), gra()
show()